package com.day1013.morning;

public class RunThread implements Runnable {
    private int meters = 1000; //共跑1000米

    public synchronized void go(){
//        for (int i = 100; i <= 1000; i+=100) {
//            for (int j = 10; j <= 100 ; j+=10) {
//                System.out.println("选手" + Thread.currentThread().getName() + "跑完10米");
//                try {
//                    Thread.sleep(500);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//            System.out.println("选手" + Thread.currentThread().getName() + "跑完了100米，换下一个选手。");
//            try {
//                Thread.sleep(500);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
        System.out.println(Thread.currentThread().getName()+"拿到接力棒！");
        for (int i = 0; i < 100; i += 10) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "跑了" + (i + 10)
                    + "米！");
        }
        meters-=100;

    }
    @Override
    public void run() {
        while (true) {
            if(meters<=100){
                break;
            }
            go();
        }

    }
}
